'''
@author：luchaopeng
@CreateTime:2019/11/5
@E-mail:2295747122@qq.com
@Site:
'''

import time

#作业1 使用count统计类属性调用次数

print('='*66)
print('作业1')
'''
定义学生类
'''
class Student(object):
	#初始化count
	count = 0
	def __init__(self, name,score):
		self.name = name
		Student.count += 1 #每调用一次，count+1
		self.score = score
	#使用print_score方法打印学生姓名和分数，count的值
	def print_score(self):
		print('%s: %s' % (self.name, self.score))
		print("测试count的值：%d" % (self.count))

Stu = Student('lili',99) #类的实例化
Stu1 = Student('lihua',67)
Stu.print_score()        #调用print_score方法
print(Stu.name,Stu1.name) #打印学生名字


#作业2

print('='*66)
print('作业2')

#定义装饰器metric
def metric(fn):
	#定义函数result_fn,用来执行函数的时间，返回result_fn函数
	def result_fn():
		start_time = time.time()
		fn() #在函数里调用函数，并返回
		end_time = time.time()
		print('耗时：{:.4f}s'.format(end_time - start_time))
	return result_fn

@metric
#这里相当于: Student = metric(Student)

def Student():
	sun1 = 0
	for i in range(1,3):
		sun1 += i
		time.sleep(1)
	print('sun1的值：',sun1)
	return sun1
Student()

